﻿using System.Data;
using ECM7.Migrator.Framework;

namespace music.domain.Migrations
{
	[Migration(8)]
	public class Migration008_Comments : Migration
	{
		public override void Apply()
		{
			Database.AddTable("Comments",
				new Column("Id", DbType.Guid, ColumnProperty.PrimaryKey, "newid()"),
				new Column("UserId", DbType.Guid, ColumnProperty.NotNull),
				new Column("SongId", DbType.Guid, ColumnProperty.NotNull),
				new Column("Created", DbType.DateTime, ColumnProperty.NotNull, "getdate()"),
				new Column("Text", DbType.String.WithSize(int.MaxValue))
			);

			Database.AddForeignKey("FK_CommentsSongs", "Comments", "SongId", "Songs", "Id");
			Database.AddForeignKey("FK_CommentsUsers", "Comments", "UserId", "Users", "Id");
		}

		public override void Revert()
		{
			Database.RemoveConstraint("Comments", "FK_CommentsUsers");
			Database.RemoveTable("Comments");
		}
	}
}